var randomString = require('random-string');
var redisManager =require('../proxy/redisManager');
var config = require('../config').config;

/**
 * 检查用户合法性
 * @param req
 * @param res
 * @param next
 */
exports.checkAuth = function(req, res, next){

}

exports.setCurrUser = function(req, res, next){

}

exports.csrf = function(req, res, next){
    console.log('当前token:' +req.session.token);
    if(req.body._csrf){
        if(req.session.token ===  req.body._csrf){
            console.log('可以通过');
            req.session.token = randomString({length: 20});
            res.locals.token = req.session.token
            console.log('刷新token: '+res.locals.token);
        }else{
            return res.send({data: '重复提交'})
        }
    }else{
        req.session.token = randomString({length: 20});
        res.locals.token = req.session.token
    }
    next();
}
